package cn.net.xyan.easy.gwt.client.ui;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.dom.client.Style;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * Created by zarra on 16/2/18.
 */
public class MainFrame  implements EntryPoint {

    int headHeight = 50;
    int leftWidth = 225;

    DockLayoutPanel contentPanel;

    SideBar sideBar;

    Navbar navbar;

    Panel rightPanel;

    Widget contentWidget;

    protected DockLayoutPanel getContentPanel() {
        return contentPanel;
    }

    protected SideBar getSideBar() {
        return sideBar;
    }

    protected Navbar getNavbar() {
        return navbar;
    }

    protected Panel getRightPanel() {
        return rightPanel;
    }

    public int getHeadHeight() {
        return headHeight;
    }

    public void setHeadHeight(int headHeight) {
        this.headHeight = headHeight;
    }

    public int getLeftWidth() {
        return leftWidth;
    }

    public void setLeftWidth(int leftWidth) {
        this.leftWidth = leftWidth;
    }

    public Widget getContentWidget() {
        return contentWidget;
    }

    public void setContentWidget(Widget contentWidget) {
        if (this.contentWidget != null){
            this.contentWidget.removeFromParent();
            this.contentWidget = null;
        }
        this.contentWidget = contentWidget;
        this.rightPanel.add(this.contentWidget);
    }

    protected Panel setupUI(){
        if (contentPanel == null){
            contentPanel = new DockLayoutPanel(Style.Unit.PX);

            contentPanel.getElement().getStyle().setMarginLeft(0, Style.Unit.PX);
            contentPanel.getElement().getStyle().setMarginRight(0, Style.Unit.PX);

            contentPanel.setHeight("100%");
            contentPanel.setWidth("100%");


            navbar = new Navbar();

            contentPanel.addNorth(navbar,getHeadHeight());

            navbar.getElement().getParentElement().getStyle().setOverflow(Style.Overflow.VISIBLE);


            DockLayoutPanel left = new DockLayoutPanel(Style.Unit.PX);

            left.getElement().getStyle().setBackgroundColor("#fafafa");

            rightPanel = new DockLayoutPanel(Style.Unit.PX);

            //rightPanel.getElement().getStyle().setBackgroundColor("yellow");

            rightPanel.getElement().getStyle().setBorderWidth(1, Style.Unit.PX);
            rightPanel.getElement().getStyle().setBorderColor("#e0e0e0");

            sideBar = new SideBar();
            left.add(sideBar);


            contentPanel.addWest(left,getLeftWidth());
            contentPanel.add(rightPanel);

        }

        return  contentPanel;
    }



    @Override
    public void onModuleLoad() {
        RootLayoutPanel.get().add(setupUI());
    }
}
